// import { defineAsyncComponent } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import MenuLeftLayout from '@/layouts/MenuLeftLayout.vue'

const routes = [
  {
    name: '门户',
    path: '/',
    component: () => import('@/views/portal')
  },
  {
    name: 'login',
    path: '/login',
    component: () => import('@/views/login')
  },
  {
    name: '单点登录',
    path: '/sso-login',
    component: () => import('@/views/sso-login')
  },
  {
    name: '404',
    path: '/404',
    component: () => import('@/layouts/404.vue')
  },
  {
    name: 'reports',
    path: '/reports',
    component: MenuLeftLayout,
    redirect: '/report',
    children: [
      {
        name: 'report',
        path: '/report',
        component: () => import('@/views/report')
      }
    ]
  },
  {
    name: '/refund-query',
    path: '/refund-query',
    component: () => import('@/views/out-registration/statistics/refund-query')
  },
  {
    name: '医生开单项目统计',
    path: '/report/doctor-order-item-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/doctor-order-item-statistics')
  },
  {
    name: '医生执行项目统计',
    path: '/report/doctor-execute-item-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/doctor-execute-item-statistics')
  },
  {
    name: '门诊医生工作量统计',
    path: '/report/doctor-workload-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/doctor-workload-statistics')
  },
  {
    name: '门诊工作量统计-报表',
    path: '/report/out-workload-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/out-workload-statistics')
  },
  {
    name: '接待情况统计',
    path: '/report/reception-situation-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/reception-situation-statistics')
  },
  {
    name: '月度手术按医生统计',
    path: '/report/operation-doctor-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/operation-doctor-statistics')
  },
  {
    name: '实收金额统计',
    path: '/report/receipts-amount-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/receipts-amount-statistics')
  },
  {
    name: '开单药品统计',
    path: '/report/ordering-drugs',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/ordering-drugs')
  },
  {
    name: '推荐渠道统计-按登记',
    path: '/report/recommend-channel-register',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/recommend-channel-register')
  },
  {
    name: '接待月度统计',
    path: '/report/monthly-reception-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/monthly-reception-statistics')
  },
  {
    name: '手术按医生统计',
    path: '/report/monthly-statistics-by-doctor',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/monthly-statistics-by-doctor')
  },
  {
    name: '项目费用查询',
    path: '/report/project-cost-inquiry',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/project-cost-inquiry')
  },
  {
    name: '门诊就诊查询',
    path: '/report/statistics-register-query',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/statistics-register-query')
  },
  {
    name: '门诊收费结算查询',
    path: '/report/out-charge-settlement',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/out-charge-settlement')
  },
  {
    name: '门诊类别日统计报表',
    path: '/report/out-category-daily-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/out-category-daily-statistics')
  },
  {
    name: '门诊费用按类别统计',
    path: '/report/out-cost-category-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/out-cost-category-statistics')
  },
  {
    name: '住院费用按类别统计',
    path: '/report/in-cost-category-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/in-cost-category-statistics')
  },
  {
    name: '住院病人费用明细查询',
    path: '/report/inp-fees-details-query',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/inp-fees-details-query')
  },
  {
    name: '手术数量统计',
    path: '/report/surgeries-number-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/surgeries-number-statistics')
  },
  {
    name: '手术患者明细',
    path: '/report/surgical-patient-details',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/surgical-patient-details')
  },
  {
    name: '手术工作量统计',
    path: '/report/surgical-workload-statistics',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/surgical-workload-statistics')
  },
  {
    name: '门诊医生用药查询(西成药)',
    path: '/report/outpatient-xmedicine-query',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/outpatient-xmedicine-query')
  },
  {
    name: '门诊医生用药查询(中草药)',
    path: '/report/outpatient-zmedicine-query',
    meta: { auth: 1 },
    component: () => import('@/views/report/custom/outpatient-zmedicine-query')
  },
  {
    path: '/:catchAll(.*)',
    redirect: '/'
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes: routes
})
router.beforeEach(async (to) => {
  localStorage.removeItem('columnCode')
  setTimeout(() => {
    setPrintSize('A4', 'portrait')
  }, 1000)
  if (!document.cookie && to.path !== '/login' && to.path !== '/sso-login' && to.meta.auth !== 1) {
    return router.push({ path: '/login' })
  }
})
export { router, routes }
